FROM php:8.2-fpm AS php82_fpm
WORKDIR "/www"
# sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list.d/ \
#     && sed -i s@/deb.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list \
#     && 
RUN apt-get clean \
    && apt-get update \
    && apt-get -y --no-install-recommends install libzip-dev libwebp-dev libjpeg-dev libpng-dev libfreetype6-dev openssl libc-ares-dev libc-ares2 libcurl4-openssl-dev \
    #php redis
    && curl -L -o /tmp/redis.tar.gz https://github.com/phpredis/phpredis/archive/5.3.4.tar.gz \
    && tar xfz /tmp/redis.tar.gz \
    && rm -r /tmp/redis.tar.gz \
    && mkdir -p /usr/src/php/ext \
    && mv phpredis-5.3.4 /usr/src/php/ext/redis \
    # gd
    && apt-get install --allow-downgrades -y  zlib1g-dev libz-dev libfreetype6-dev libjpeg62-turbo-dev libpng-dev \
    && docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \
    # swoole
    #pecl install -D 'enable-sockets="no" enable-openssl="yes" enable-http2="yes" enable-mysqlnd="yes" enable-swoole-json="no" enable-swoole-curl="yes" enable-cares="yes"' swoole \
    # install ext
    && docker-php-ext-install -j$(nproc) gd\
    && docker-php-ext-install redis \
    && docker-php-ext-install zip \
    && docker-php-ext-install bcmath \
    && docker-php-ext-install pdo_mysql \
    && docker-php-ext-install sockets \
    && apt-get clean && apt-get autoremove \
    && rm -rf /var/lib/apt/lists/* \
    #composer
    && php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" \
    && php composer-setup.php \
    && rm composer-setup.php \
    && mv composer.phar /usr/local/bin/composer \
    && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ \
    && php -v && php -m
# && echo "#!/bin/bash" > /tmp/init.sh \
# && echo "cd /www/admin-server" >> /tmp/init.sh \
# && echo "composer install" >> /tmp/init.sh \
# && echo "php artisan key:generate" >> /tmp/init.sh \
# && echo "php artisan storage:link" >> /tmp/init.sh \
# && echo "php artisan jwt:secret" >> /tmp/init.sh \
# && chmod +x /tmp/init.sh

# CMD [ "/tmp/init.sh" ]